<?php

/**
 * @author Martin Pernica
 * @copyright 2008
 */
 echo '<h2><a href="index.php?p=build">Zpět</a></h2><br />';
 
 if(!empty($_POST['type'])){
	if($_POST['type'] == 'module'){
        $module_path = './modules/'.$_POST['module'].'/'.$_POST['module'].'.php';
	}else{
        $module_path = '';
	}
    
	$query = $GLOBALS['db']->query('UPDATE '.$GLOBALS['db_prefix']."rightblock SET type = '".$_POST['type']."', text = '".$_POST['text']."', module_path = '".$module_path."', weigh = '".intval($_POST['weigh'])."', active = '".intval($_POST['active'])."' WHERE id = '".intval($_GET['id'])."'");
	echo '<h2>Položka upravena !</h2>';
 }
 
$query = $GLOBALS['db']->query("SELECT * FROM ".$GLOBALS['db_prefix']."rightblock WHERE id = '".intval($_GET['id'])."'");
$data = $query->fetch_array();
$type = array("text" => "Text", "module" => "Modul");
echo '<form action="'. $_SERVER['PHP_SELF'] .'?'. $_SERVER['QUERY_STRING'] .'" method="POST">
<table>
<tr><td>Typ :</td><td><select name="type" size="1">
';
foreach ($type as $key => $val){
	$selected = ($data['type'] == $key) ? 'selected="selected"' : '';
        echo '<option value="'.$key.'" '.$selected.'>'.$val.'</option>';
}
echo'
</select>
</td></tr>
<tr><td>Text (nepovinné u typu modul):</td></tr>
<tr><td><textarea name="text" cols="40"  rows="5" class="wysiwyg" >'.$data['text'].'</textarea></td></tr>
<tr><td>Modul (nepovinné u typu text):</td><td>
<select name="module" size="1">
<option value=" "> </option>
';
$modules = dirlist('../modules');
for($i = 0; !empty($modules[$i]); $i++){
	$temp = array_reverse(explode('/', $data['module_path']));
	$temp[0] = str_replace('.php', '', $temp[0]);
	if($temp[0] == $modules[$i]){
        echo '<option value="'.$modules[$i].'" selected="selected">'.$modules[$i].'</option>';
	}else{
	echo '<option value="'.$modules[$i].'">'.$modules[$i].'</option>';
	}
}
$active = ($data['active'] == 1) ? 'checked="checked"' : '';
echo '
</select>
</td></tr>
<tr><td>Váha :</td><td><input type="text" name="weigh" size="10" value="'.$data['weigh'].'" /></td></tr>
<tr><td>Aktivní :</td><td><input type="checkbox" name="active" value="1" '.$active.' /></td></tr>
<tr><td><input type="submit" value="Odeslat" /></td></tr>
</table>
</form>
';
?>